\chapter{Linux Conventions}

This chapter describes some details that are only relevant to 
GNU/Linux systems and the Linux kernel.

\section{Execution of 32-bit Programs}

% Let's follow Sparc64 and MIPS64

The \xARCH processors are able to execute 64-bit \xARCH and also
32-bit ia32 programs.  Libraries conforming to the \intelabi will live
in the normal places like \path{/lib}, \path{/usr/lib} and
\path{/usr/bin}.  Libraries following the \xARCH, will use
\path{lib64} subdirectories for the libraries, e.g \path{/lib64} and
\path{/usr/lib64}.  Programs conforming to \intelabi and to the \xARCH
ABI will share directories like \path{/usr/bin}.  In particular, there
will be no \path{/bin64} directory.

\section{AMD64 Linux Kernel Conventions}

The section is informative only.

\subsection{Calling Conventions}

The Linux \xARCH kernel uses internally the same calling conventions as user-level
applications (see section~\ref{sec-calling-conventions} for details).
User-level applications that like to call system calls should use the
functions from the C library.  The interface between the C library and
the Linux kernel is the same as for the user-level applications with
the following differences:
\begin{enumerate}
\item User-level applications use as integer registers for passing the
  sequence \RDI, \RSI, \RDX, \RCX, \reg{r8} and \reg{r9}.  The kernel
  interface uses \RDI, \RSI, \RDX, \reg{r10}, \reg{r8} and \reg{r9}.
\item A system-call is done via the \code{syscall} instruction.  The
  kernel destroys registers \RCX and \reg{r11}.
\item The number of the syscall has to be passed in register \RAX.
\item System-calls are limited to six arguments, no argument is passed
  directly on the stack.
\item Returning from the \code{syscall}, register \RAX contains the
  result of the system-call.  A value in the range between -4095 and
  -1 indicates an error, it is \code{-errno}.
\item Only values of class INTEGER or class MEMORY are passed to the
  kernel.
\end{enumerate}

\subsection{Stack Layout}

The Linux kernel may align the end of the input argument area to a
8, instead of 16, byte boundary.  It does not honor the
\textindex{red zone} (see section~ \ref{sec-stack-frame}) and therefore
this area is not allowed to be used by kernel code.  Kernel code should
be compiled by GCC with the option \code{-mno-red-zone}.

\subsection{Miscellaneous Remarks}

Linux Kernel code is not allowed to change the x87 and SSE units.  If
those are changed by kernel code, they have to be restored properly
before sleeping or leaving the kernel.  On preemptive kernels also
more precautions may be needed.


%%% Local Variables:
%%% mode: latex
%%% TeX-master: "abi"
%%% End:
